package ltesim.xmlParser.xmlData;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xirka
 * Abstract container of parsed configuration data
 */
public abstract class XMLDataset {

	private final static String DEFAULTVAL = "00";
	private Map<String, String> prop = new HashMap<String, String>(20);

	/**
	 * Get the list of available keys
	 * @return
	 */
	protected abstract String[] getAvailableKeys();

	/**
	 * Create a new empty XMLDataset
	 */
	public XMLDataset() {
		for (String key : getAvailableKeys()) {
			prop.put(key, DEFAULTVAL);
		}
	}

	/**
	 * Assign the value _value to a key _key
	 * @param _key
	 * @param _value
	 */
	public void setData(String _key, int _value) {
		if (prop.containsKey(_key)) {
			prop.put(_key, "" + _value);
		}
	}

	/**
	 * Assign the value _value to a key _key
	 * @param _key
	 * @param _value
	 */
	public void setData(String _key, String _value) {
		if (prop.containsKey(_key)) {
			prop.put(_key, _value);
		}
	}

	/**
	 * Get the data assigned to key _key
	 * @param _key
	 * @return Integer
	 */
	public int iGetData(String _key) {
		if (prop.containsKey(_key)) {
			return Integer.parseInt(prop.get(_key));
		} else {
			return Integer.parseInt(DEFAULTVAL);
		}
	}
	
	/**
	 * Get the data assigned to key _key
	 * @param _key
	 * @return String
	 */
	public String sGetData(String _key) {
		if (prop.containsKey(_key)) {
			return prop.get(_key);
		} else {
			return DEFAULTVAL;
		}
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		String retVal = "---\n";
		for (String key : getAvailableKeys()) {
			retVal += key + ": " + sGetData(key) + "\n";
		}
		return retVal;
	}

}
